<template>
  <el-dialog
    title="修改"
    :visible.sync="dialogShow"
    width="40%"
    :before-close="handleClose"
    :close-on-click-modal="false"
  >
    <div>
      <el-form ref="refForm" :rules="formRules" :model="formData" size="mini" label-width="100px">
        <el-form-item label="加急:" prop="urgent">
          <el-input v-model="formData.urgent" placeholder="请输入加急 " />
        </el-form-item>
        <el-form-item label="复尺确认时间:" prop="rulerConfirmTime">
          <el-date-picker
            v-model="formData.rulerConfirmTime"
            type="date"
            clearable
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
          />
        </el-form-item>
        <el-form-item label="复尺确认备注:" prop="rulerConfirmRemark">
          <el-input
            v-model="formData.rulerConfirmRemark"
            type="textarea"
            placeholder="请输入复尺确认备注"
            maxlength="1000"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="是否可解锁 :" prop="isLock">
          <el-radio-group v-model="formData.isLock">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>

      </el-form>
    </div>
    <div slot="footer">
      <el-button size="mini" @click="handleClose">取 消</el-button>
      <el-button type="primary" size="mini" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { saveData, queryDetail } from '@/api/autoDesignTask'
export default {
  name: 'EditUrgent',
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    detailData: {
      type: [String, Object],
      default: ''
    }
  },
  data() {
    return {
      formData: {
        id: '',
        urgent: '',
        rulerConfirmTime: '',
        rulerConfirmRemark: '',
        isLock: undefined
      },
      formRules: {}
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  async created() {
    if (this.detailData) {
      const { id,
        urgent,
        rulerConfirmTime,
        rulerConfirmRemark,
        isLock = undefined } = this.detailData
      this.formData = { id,
        urgent,
        rulerConfirmTime,
        rulerConfirmRemark,
        isLock }
    }
  },
  mounted() {},
  methods: {
    submitForm() {
      queryDetail(this.detailData.id).then(res => {
        if (res.success) {
          saveData(this.formData).then(res => {
            if (res.success === 1) {
              this.$message.success('修改成功')
              this.handleClose()
              this.$emit('success')
            }
          })
        }
      })
    },
    handleClose() {
      this.dialogShow = false
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped lang="scss">

</style>
